// 屏幕适配工具类

// 获取设备信息
const systemInfo = wx.getSystemInfoSync();

// 设计稿尺寸（以 iPhone 6 为基准）
const designWidth = 750;
const designHeight = 1334;

// 计算比例
const scale = systemInfo.windowWidth / designWidth;
const scaleH = systemInfo.windowHeight / designHeight;

// 适配方法
function toRpx(px) {
  return Math.floor(px * scale * 2) / 2; // 保留一位小数
}

function toPx(rpx) {
  return Math.floor(rpx / scale / 2) / 2; // 保留一位小数
}

// 根据屏幕密度调整字体大小
function adaptFontSize(size) {
  const baseSize = size;
  const adaptedSize = baseSize * scale;
  return Math.round(adaptedSize);
}

// 适配padding
function adaptPadding(top, right, bottom, left) {
  return {
    paddingTop: toRpx(top),
    paddingRight: toRpx(right),
    paddingBottom: toRpx(bottom),
    paddingLeft: toRpx(left)
  };
}

// 适配margin
function adaptMargin(top, right, bottom, left) {
  return {
    marginTop: toRpx(top),
    marginRight: toRpx(right),
    marginBottom: toRpx(bottom),
    marginLeft: toRpx(left)
  };
}

module.exports = {
  toRpx,
  toPx,
  adaptFontSize,
  adaptPadding,
  adaptMargin,
  scale,
  scaleH,
  systemInfo
};